<?php

namespace Modules\Order\Http\Controllers\Admin\V1;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;


use Modules\Order\Entities\BaseOrder as Order;

use Validator;
use ThrowException;
use Auth;

class OrderStatController extends Controller
{
    public function totalStat(Request $req)
    {
        $rule = [
        ];

        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest();

        $key = $req->input('key') ?: '';
        $orderType = $req->input('type');

        $options = $req->all();
        $options['where'][] = ['user_id', '>', '500'];
        // $options = [
        //     'scopes' => [
        //         'visible'
        //     ],
        //     'key' => $key
        // ];

        $builder = Order::getBuilder($options);

        $options['scopes']['type'] = $orderType;
        $builderType = Order::getBuilder($options);

        $stat = [
            // 'pending' => Order::status('pending')->type($orderType)->visible()->search($key)->count(),
            'deliver_pending' => Order::getBuilder($options)->status('deliver_pending')->count(),
            'pay_pending' => Order::getBuilder($options)->status('pay_pending')->count(),
            'delivered' => Order::getBuilder($options)->status('delivered')->count(),
            'aftersale_pending' => Order::getBuilder($options)->status('aftersale_pending')->count(),
            'completed' => Order::getBuilder($options)->status('completed')->count(),
            'all' => Order::getBuilder($options)->count(),
            'offline_used' => Order::getBuilder($options)->status('offline_used')->count(),
            'marked' => Order::getBuilder($options)->status('marked')->count(),
            'closed' => Order::getBuilder($options)->status('closed')->count(),
            'package_all' => Order::type('package')->visible()->count(),
            'product_all' => Order::type('product')->visible()->count(),
            'other_all' => Order::type('other')->visible()->count(),
            'activity_all' => Order::type('activity')->where('user_id', '>', 500)->visible()->count(),
        ];

        return [
            'info' => $stat
        ];
    }
}
